Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
point /username to /[user]/[tab].js and not [user]/index.js in nextjs

I'm attempting to create a user profile page that generates content based on the current tab the user is in.

The tab is decided based on what is passed in the URL (e.g. /username/tab1). The only issue with this is that one of the valid tabs the user can visit actually has a blank value (/username, to get the default tab).

However, when you enter this into the browser, Next automatically assumes I want to retrieve /[user]/index.js (which doesn't exist), when in actuality what I want to get is /[user]/[tab].js and pass a blank value to the tab property in context.query.

Is this possible without creating a separate index.js and [tab].js file?

// Exported inside /pages/[user]/[tab].js
export const getServerSideProps = async (context) => {
    const { page, tab } = context.query;

    // When we're on /username/foo it should output "foo".
    // When we're on /username it should output "".
    console.log(tab); 
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can achieve this using an optional catch-all route.

So, rename your [tab].js as [[...tab]].js, so it will catch also the requests to /username without a tab. Then in your code you'll handle tab as optional.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!